require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../lib/flexible')
require('../font/iconfont.css')
require('../css/introduce.less')
    //引入axios
const axios = require('axios')

document.addEventListener('DOMContentLoaded', function() {
    const name = document.querySelector('#name')
    const desc = document.querySelector('#desc')
    const imgurl = document.querySelector('#imgurl')
    const calorie = document.querySelector('#calorie')
    const time = document.querySelector('#time')
    const peoplenum = document.querySelector('#peoplenum') //观看人数
    const frequency = document.querySelector('#frequency') //频率
    const instrument = document.querySelector('#instrument') //机械
    const goBack = document.querySelector('#goBack')
    const video = document.querySelector('video')
    const preview = document.querySelector('.preview')


    let id = sessionStorage.cid
    console.log(id);

    axios.get('http://139.9.177.51:8099/sports/courseDetail?id=' + id)
        .then(function(res) {
            let data = res.data.data
            console.log(data);
            name.textContent = data.name
            desc.textContent = data.desc
            imgurl.src = 'http://139.9.177.51:8099' + data.imgurl
            calorie.textContent = data.calorie
            time.textContent = data.time
            peoplenum.textContent = data.peoplenum
            frequency.textContent = data.frequency
            instrument.textContent = data.instrument
            video.src = 'http://139.9.177.51:8099' + data.fragments[parseInt(`${id-4 < 0 ? 0 : id-4}`)].videoUrl
            video.poster = 'http://139.9.177.51:8099' + data.fragments[parseInt(`${id-4 < 0 ? 0 : id-4}`)].imgUrl
                // console.log(data.fragments.videoUrl);
                // console.log(data.fragments.imgUrl);
                //将数据存储到临时存储
            sessionStorage.fragments = JSON.stringify(data.fragments)
        })

    goBack.addEventListener('click', function() {
        history.go(-1)
    })

    preview.addEventListener('click', function() {
        video.play()
    })

    video.addEventListener('play', function() {
        preview.style.display = 'none'
    })
    video.addEventListener('pause', function() {
        preview.style.display = 'block'
    })

})